<?php
$option= array(
            'inputDefaults' => array(
                'div' => array(
                	'class' => 'form-group'
                ),
                'label' => array(
                	'class' => ' col-md-push'
                ),
                'between' => '<div class="col-lg-8 right">',
                'seperator' => '</div>',
                'after' => '</div>',
                'class' => 'form-control',
            ),
            'class' => 'form-horizontal form-stacked',
            'role' => 'form',
        );
?>
<div class="row">
	<br>
  	
  	
<div class="col-sm-12 col-md-12 ">
		<?php echo $this->Session->flash(); ?>
	</div>
	<div class="col-sm-12 col-md-12">
		<div class="page-header">
		  <h1> <?php echo __($page);?> Turno</h1>
		</div>

		<div id="signup" class="lock-screen">
				
				
			<!--	<div class="alert alert-danger alert-dismissable" id>
				  <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
				  <strong>Error!</strong> 
				  <label>Better check yourself, you're not looking too good.</label>
				</div> -->

				<?php echo $this->Form->create('Events',$option); ?>
					<fieldset>
						<?php echo $this->Form->input('branch_id' ,array( 'class'=>'form-control chosen-select ','label' => array( 'text' => __('Sucursal:'),'class' => 'col-lg-2 control-label'),'empty'=>'Sucursal' ))?>
						<div class="form-group">
					    <label for="inputEmail3" class="col-sm-2 control-label">Servicio</label>
					    <div class="col-sm-4">
					        <select class=' form-control chosen-select'  id='EventsServiceIdCode'>
					        	<option value=0 selected='selected'> Ingrese Codigo de Servicio</option>
						      	<?php foreach ($services_codes as $key=>$val):?>
						      		<option value='<?php echo $key?>'><?php echo $val?></option>
						      	<?php endforeach;?>
						    </select>
					    </div>
					    <div class="col-sm-4">
					      <!-- <input type="email" class="form-control" id="inputEmail3" placeholder="Email"> -->
					      <select class=' form-control chosen-select' id='EventsServiceIdName'>
					      	<option value=0 selected='selected'> Ingrese Nombre de Servicio</option>
					      	<?php foreach ($services as $key=>$val):?>
					      		<option value='<?php echo $key?>'><?php echo $val?></option>
					      	<?php endforeach;?>
					      </select>
					    </div>
						    
				  	</div>
					  <div style='display:none;'>
						 	<?php echo $this->Form->input('service_id' ,array( 'class'=>'form-control chosen-select ','label' => array( 'text' => __('Servicio:'),'class' => 'col-lg-2 control-label'),'empty'=>'Servicio' ))?>
						</div>


						<div class="form-group">
					    <label for="inputEmail3" class="col-sm-2 control-label">Clientes</label>
					    <div class="col-sm-4">
					        <select class=' form-control chosen-select'  id='EventsClientIdDni'>
					        	<option value=0 selected='selected'> Ingrese Dni</option>
						      	<?php foreach ($clients_codes as $key=>$val):?>
						      		<option value='<?php echo $key?>'><?php echo $val?></option>
						      	<?php endforeach;?>
						    </select>
					    </div>
					    <div class="col-sm-4">
					      <!-- <input type="email" class="form-control" id="inputEmail3" placeholder="Email"> -->
					      <select class=' form-control chosen-select' id='EventsClientIdName'>
					      	<option value=0 selected='selected'> Ingrese Nombre</option>
					      	<?php foreach ($clients as $key=>$val):?>
					      		<option value='<?php echo $key?>'><?php echo $val?></option>
					      	<?php endforeach;?>
					      </select>
					    </div>
						    
				  	</div>
					  <div style='display:none;'>
						 	<?php echo $this->Form->input('client_id',array( 'class'=>'form-control','label' => array( 'text' => __('Cliente:'),'class' => 'col-lg-2 control-label' ),'empty'=>'Cliente', 'multiple' => false));?>
						</div>

<!--
						<?php echo $this->Form->input('client_id',array( 'class'=>'form-control chosen-select ','label' => array( 'text' => __('Cliente:'),'class' => 'col-lg-2 control-label' ),'empty'=>'Cliente', 'multiple' => false));?>

-->
						<?php echo $this->Form->input('date',array( 'type'=>'text' ,'label' => array( 'text' => __('Fecha:'),'class' => 'col-lg-2 control-label' )));?>
						<div class="form-group">
					    	<div class="col-sm-offset-2 col-sm-8">

								<div class="panel-body">
							        <div id="turnos"></div>
						      	</div>
								<div  id="accordion">
								  	<!-- <h4 class="panel-title">
								        <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
								          Collapsible Group Item #2
								        </a>
							      	</h4> -->
								    <div id="collapseTwo" class="panel-collapse collapse">
								      <div class="panel-body">
								        <div id="turnos"></div>
								      </div>
								    </div>
								</div>
							</div>
						</div>
						<?php echo $this->Form->input('time_from',array( 'label' => array( 'text' => __('Horario:'),'class' => 'col-lg-2 control-label' ),'empty'=>'Tiempo'));?>
						
						<!-- <input class="form-control" type="text" data-mask="99/99/9999" placeholder=""> -->
						<?php echo $this->Form->input('paid',array( 'label' => array( 'text' => __('Paga:'),'class' => 'col-lg-2 control-label ','data-mask'=>"99/99/9999",'placeholder'=>'dd/mm/aaaa' )));?>
						
						<div class="form-group">
						<label class="col-lg-2 control-label" for="EventsPaidTotal">Pago Total:</label>
						<div class="col-lg-8 right">
							<input id="EventsPaidTotal" class="" type="checkbox" value="1" seperator="</div>" name="data[Events][paid_total]">
						</div>
						</div>
						<div class="form-group">
						<label class="col-lg-2 control-label" for="EventsPaidTotal">Canje:</label>
						<div class="col-lg-8 right">
							<input id="EventsPaidTotal" class="" type="checkbox" value="1" seperator="</div>" name="data[Events][exchange]">
						</div>
						</div>

						<!-- <?php echo $this->Form->input('paid_total');?> -->
										
						<?php echo $this->Form->input('description',array( 'type'=>'textarea','label' => array( 'rows' => '5', 'cols' => '5','text' => __('Descripción:'),'class' => 'col-lg-2 control-label' )));?>								
					<div class="form-group">
					    <div class="col-sm-offset-2 col-sm-10">
					      
					      <?php echo $this->Html->link(__('Cancelar', true), array('controller' => 'clients', 'action' => 'index' ),array('class'=>'btn btn-primary')); ?> 	
					      <button type="submit" class="btn btn-info">Guardar</button>
					    </div>
					  </div>
					</fieldset>	

				<?php echo $this->Form->end(); ?>
			
		</div>																																																																						
	</div>
	<!-- login container End here -->
</div>

<script type="text/javascript">
	
	function check_service_load(){
		var sid = $("#EventsServiceId").val();		
		if( sid!='')
		{
			$("#EventsServiceIdCode").val(sid).trigger("chosen:updated");	
			$("#EventsServiceIdName").val(sid).trigger("chosen:updated");	
		}	
	}
	
	$(function(){		
		check_service_load();
		$(".chosen-select").chosen({no_results_text: "No hay Resultados!"});
        $('#EventsDate').datetimepicker({ format: 'DD-MM-YYYY',
        language: 'es',pickTime: false});
		$('#EventsTimeFrom').datetimepicker({
			format:'hh:mm',
			minuteStep:20,
                    pickDate: false
        });

      $("#EventsDate").change(function()
    	{
        	
      	var date= $(this).val();
      	var event_service_id= $("#EventsServiceId").val();
      	var event_branch_id= $("#EventsBranchId").val();
      	var date_convert = date.split('-');

      	if(event_branch_id==''){
					alert("Debe Selecionar sucursal");						
					$("#EventsBranchId").focus();
				}else{
        	var date_events= false;
        	var url="/events/get_by_date/"+date;
					$.ajax({ url:url ,dataType: "json", async: false,success:function(data){			
						date_events =  data;
					}});

					//console.debug(" new_events: %o",date_events);
					$("#turnos").fullCalendar( 'destroy' );
        	$("#turnos").fullCalendar(
        		{
	        		year:date_convert[2],
	        		month:date_convert[1]-1,
	        		date:date_convert[0],
	        		defaultView: 'agendaDay',
		        	height: 350,		
		        	minTime: 8,
							maxTime: 21,	
		   				timeFormat: {
			    		agenda: 'h(:mm)t{ - h(:mm)t}',
			    			'': 'h(:mm)t{-h(:mm)t }'
			   			},
					   	monthNames: ["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" ], 
					   	monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],
					   	dayNames: [ 'Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
					   	dayNamesShort: ['Dom','Lun','Mar','Mié','Jue','Vie','Sáb'],	
							events: date_events,			
							dayClick:function(date, allDay, jsEvent, view){
							var h = date.getHours();
							var m = date.getMinutes();
							//var s = date.getSeconds();
							if (h < 10) h = '0' + h;
							if (m < 10) m = '0' + m;
							//if (s < 10) s = '0' + s;
							time_from = h + ':' + m ;//+ ':' + s;					
		            		//console.debug("time_from: %o", time_from);
		            		$('#EventsTimeFrom').val(time_from);
							}			
        		}
        	);
				}
      });     
		/* Clone service selected */
		$("#EventsServiceIdCode").change(function(){
			var id= $(this).val();
			$("#EventsServiceIdName").val(id).trigger("chosen:updated");
			//EventsServiceId
			$("#EventsServiceId").val(id).trigger("chosen:updated");
		});
		$("#EventsServiceIdName").change(function(){
			var id= $(this).val();
			$("#EventsServiceIdCode").val(id).trigger("chosen:updated");
			$("#EventsServiceId").val(id).trigger("chosen:updated");
		});

		$("#EventsClientIdDni").change(function(){
			var id= $(this).val();
			$("#EventsClientIdName").val(id).trigger("chosen:updated");
			//EventsServiceId
			$("#EventsClientId").val(id).trigger("chosen:updated");
		});
		$("#EventsClientIdName").change(function(){
			var id= $(this).val();
			$("#EventsClientIdDni").val(id).trigger("chosen:updated");
			$("#EventsClientId").val(id).trigger("chosen:updated");
		});
		
		
		

		if($("#EventsClientId option:selected").length){
			var client_id = $("#EventsClientId").val();
			//.debug("===> Client_id Load: %o", client_id);
			$("#EventsClientIdDni").val(client_id).trigger("chosen:updated");
			$("#EventsClientIdName").val(client_id).trigger("chosen:updated");
		
		}

		/*$("form").submit(function(){

			var result = true;

			if($("#EventsBranchId option:selected").length==0){
				result = false;
			}

			if($("#EventsServiceId option:selected").length==0){
				result = false;
			}	
			if($("#EventsClientId option:selected").length==0){
				result = false;
			}	

			if($("#EventsClientId option:selected").length==0){
				result = false;
			}	





			return true;



		});*/
		

		
	});
</script>



